// ArtTaskManager.cpp : Implementation of CArtTaskManager

#include "stdafx.h"
#include "ArtTaskManager.h"


#define  BUTTON_HEIGHT			25


// CArtTaskManager

STDMETHODIMP CArtTaskManager::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&IID_IArtTaskManager
	};

	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}


STDMETHODIMP CArtTaskManager::CreateTaskItem(BSTR ProgID, BSTR bstrTiTle, IDispatch** pGenericPanelItem)
{
	CComPtr<IDispatch>		pObject;
	CComPtr<IGenericPanelItem>  pItem;
	CComPtr<IGenericPanel>	pGenericPanel;
	HRESULT					hr = S_FALSE;
	HICON					hIcon = 0;

	hr = pObject.CoCreateInstance(ProgID);
	COM_ASSERT(hr);
	if (FAILED(hr))
		return hr;

	//hr = m_pHotPanel->InsertItem(-1, bstrTiTle, hIcon, 0,(IDispatch**)&pItem);
	//COM_ASSERT(hr);
	//if (FAILED(hr))
	//	return hr;

	//hr = pItem->CreateGenericPanel(bstrTiTle, hIcon, 0, (IDispatch**)&pGenericPanel);
	//COM_ASSERT(hr);
	//if (FAILED(hr))
	//	return hr;

	//hr = pGenericPanel.CoCreateInstance(CLSID_GenericPanel);
	//COM_ASSERT(hr);
	//if (FAILED(hr))
	//	return hr;

	//hr = pGenericPanel->put_DataView(pObject);
	//COM_ASSERT(hr);
	//if (FAILED(hr))
	//	return hr;

	return hr;
}


STDMETHODIMP CArtTaskManager::DeleteItem(VARIANT* varItem)
{
	//return m_pHotPanel->DeleteItem(varItem);
	return E_FAIL;
}


STDMETHODIMP CArtTaskManager::get_GenericPanel(IDispatch** pVal)
{
	if (*pVal == NULL)
		return E_INVALIDARG;

	ATLASSERT(m_pGenericPanel != NULL);

	if (m_pGenericPanel == NULL)
		return E_POINTER;

	return	m_pGenericPanel.QueryInterface(pVal);
}


STDMETHODIMP CArtTaskManager::CreateTaskManager(HWND hWndCtrl, BSTR bstrCaption)
{
	if (::IsWindow(this->m_hWnd))
		return S_OK;

	this->Create(hWndCtrl);
	ATLASSERT(NULL != this->m_hWnd);
	this->SetWindowText(bstrCaption);

	HRESULT hr = m_pGenericPanel.CoCreateInstance(CLSID_GenericPanel);
	COM_ASSERT(hr);
	if (FAILED(hr))
		return hr;

	//CRect rcClient;

	//this->GetClientRect(&rcClient);
	//hr = m_pGenericPanel->CreateGenericPanel(m_hWnd, NULL, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
	//COM_ASSERT(hr);
	//if (FAILED(hr))
	//	return hr;

	//hr = m_pHotPanel.CoCreateInstance(CLSID_HotPanel);
	//COM_ASSERT(hr);
	//if (FAILED(hr))
	//	return hr;

	//HWND hWndGeneric;
	//hr = ATL::AtlQueryOleWindowWnd(m_pGenericPanel, &hWndGeneric);
	//COM_ASSERT(hr);
	//if (FAILED(hr))
	//	return hr;

	//hr = m_pHotPanel->CreateHotPanel(hWndGeneric, NULL, HotPanelTypeTabCtrl, 0, 0, 100, 100);
	//COM_ASSERT(hr);

	return hr;
}


STDMETHODIMP CArtTaskManager::get_ShowWindow(VARIANT_BOOL* pVal)
{
	DWORD dwStyle = 0;

	if (::IsWindow(this->m_hWnd))
	{
		dwStyle = this->GetWindowLong(GWL_STYLE);
		if (dwStyle & WS_VISIBLE)
		{
			*pVal = VARIANT_TRUE;
		}else
		{
			*pVal = VARIANT_FALSE;
		}

		return S_OK;
	}

	return E_POINTER;
}


STDMETHODIMP CArtTaskManager::put_ShowWindow(VARIANT_BOOL newVal)
{
	if (::IsWindow(this->m_hWnd))
	{
		if (newVal == VARIANT_TRUE)
		{
			this->ShowWindow(SW_SHOW);
		}else
		{
			this->ShowWindow(SW_HIDE);
		}

		return S_OK;
	}

	return E_POINTER;
}


LRESULT CArtTaskManager::OnInitDialog(HWND hwndFocus, LPARAM lParam)
{
	
	return TRUE; // set focus to default control
}


LRESULT CArtTaskManager::OnSize(UINT state, CSize Size)
{

	return 0;
}



LRESULT CArtTaskManager::OnSetFocus(HWND hwndOldFocus)
{

	return 0;
}

LRESULT CArtTaskManager::OnKillFocus(HWND hwndNewFocus)
{

	return 0;
}
